package com.lagou.upload.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.lagou.entity.FileSystem;
import com.lagou.upload.FileService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("file")
public class FileUploadController {
    @Reference
    private FileService fileService;

    @PostMapping("upload")
    @ResponseBody
    public FileSystem upload(MultipartFile file) throws Exception{
        // 从页面请求中，获取上传的文件对象
        if(file!=null){
            byte[] pic = file.getBytes();
            return fileService.upload(pic,file.getOriginalFilename());
        }else
        {
            return null;
        }

    }
}
